/**
 * Created by zzw on 2016/5/20.
 * 选择银行卡
 */

$(function(){
    findAgentBandBank();
});


//查询银行卡列表
function findAgentBandBank() {
    var param = JSON.stringify({"token": localStorage.token});
    $.fn.serviceInvoke(serviceAddress.Address, 'agent_app_AgentSet', 'findAgentBandBank.action', param, function (result) {
        if (result.msg == "success") {
            if(result.list==0){
                $("#bankList").html("<div class='text-center' style='margin-top: 20px;'>没有银行卡，请<a href='../layout/addBankCard.html' target='_self'>添加</a>银行卡</div>");
            }else{
                var bankList = "";
                for (var i = 0; i < result.list.length; i++) {
                    bankList+='<div style="width: 100%;height: auto;border-bottom: 1px solid rgb(230,230,230)"><div class="container"><div style="background-color: #3e8f3e; border-radius: 8px 8px 0 0;width: 100%;height: 110px;margin-top: 10px;color: white"><div class="media" style="padding-top: 20px;width: 98%;"><div class="media-left" style="padding-left: 30px;"><a href="#"><img src="../images/'+result.list[i].bimg+'.png" class="media-object" alt=""></a></div><div class="media-body"><h4 class="media-heading">'+result.list[i].bankName+'</h4><p>'+result.list[i].bankNo+'</p></div><div class="media-right"><button class="btn btn-default" onclick="setDefult('+result.list[i].id+')" >设置默认银行卡</button></div><hr></div></div></div></div>';
                }
                $("#bankList").html(bankList);
            }
        }else{
            // alert("查询银行卡失败");
        }
    })
}

//设置默认银行卡
function setDefult(id){
    var param = JSON.stringify({"token": localStorage.token,"bankid":id});
    $.fn.serviceInvoke(serviceAddress.Address, 'agent_app_AgentSet', 'setDefaultBandBank.action', param, function (result) {
            if(result.msg == "success"){
                alert("设置默认卡成功！");
                location.href="advanceCash.html?id="+id;
            }else{
                alert("设置失败！");
            }
    })

}